package uk.ac.cam.echo.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

/**
 * @author Thom Sutcliffe, Vladimir Kovalev, Matt Thomson, Tom Smith, Mona
 *         Taebipour, Andrius Dagys
 */

public class EchoActivity extends ExtendedActivity
{
	/**
	 * Called when the activity is first created. Manages initial GUI components
	 * and handlers.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		// Display the initial layout
		setContentView(R.layout.main);

		// Handle exceptions
		Intent i = getIntent();
		if (i.hasExtra("Exception"))
		{
			showOKMessage(i.getExtras().getString("Exception"));
		}

		// Create buttons to provide functionality for the buttons in the .xml
		// files.
		final ImageView mapButton = (ImageView) findViewById(R.id.maplauncher);
		final ImageView photoButton = (ImageView) findViewById(R.id.photolauncher);
		final ImageView friendButton = (ImageView) findViewById(R.id.friendlauncher);
		final ImageView eventsButton = (ImageView) findViewById(R.id.eventslauncher);
		final ImageView scannerButton = (ImageView) findViewById(R.id.scanrfidlauncher);
		final ImageView achievementsButton = (ImageView) findViewById(R.id.achlauncher);

		mapButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent i = new Intent(self, MapActivity.class);
				self.startActivity(i);
				self.finish();
			}
		});

		photoButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent i = new Intent(self, PhotoActivity.class);
				self.startActivity(i);
				self.finish();
			}
		});

		friendButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent i = new Intent(self, FriendsActivity.class);
				self.startActivity(i);
				self.finish();
			}
		});

		eventsButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent i = new Intent(self, EventsActivity.class);
				self.startActivity(i);
				self.finish();
			}
		});

		scannerButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent i = new Intent(self, ScannerActivity.class);
				self.startActivity(i);
				self.finish();
			}
		});

		achievementsButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent i = new Intent(self, AchievementsActivity.class);
				self.startActivity(i);
				self.finish();
			}
		});
	}

	@Override
	public void onNewIntent(Intent i)
	{
		if (i.hasExtra("Exception"))
		{
			showOKMessage(i.getExtras().getString("Exception"));
		}
	}
}
